package Classic150;

import LinkedList.ListNode;

public class 旋转链表 {
    /*
        纯模拟
     */
    public ListNode rotateRight(ListNode head, int k) {
        if (k == 0 || head == null || head.next == null) return head;
        int len = 1;
        ListNode cur = head;
        while (cur.next != null) {
            cur = cur.next;
            len++;
        }
        k = len - k % len;
        if (k == len) return head;
        cur.next = head;
        while (k-- > 0) cur = cur.next;
        head = cur.next;
        cur.next = null;
        return head;
    }
}
